package com.sky.blog.util;

import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

/**
 * @author sky  2022/3/24
 * @version 1.0
 */

@Component
@Slf4j
public class DateTimeUtils {

    private final static String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static String getNowDateTime() {
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(DEFAULT_FORMAT));
    }

    public static String getNowDateTime(@Nullable String formatPattern) {
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(Objects.requireNonNull(formatPattern)));
    }
}
